// 基于 SnowLang Project (https://gitee.com/jcnc-org/snow) 的衍生作品
// 原始版权归属: Copyright © 2025 Ke Xu (Luke)
// 本实现版权归属: Copyright © 2025 Sany
// 遵循 Apache License 2.0 授权
package flow

import (
	"errors"
	"strconv"

	"gitee.com/xntk2381/cc/vm/module"
	"gitee.com/xntk2381/cc/vm/utils"
)

type JumpCommand struct{}

func (JumpCommand) Execute(parts []string, currentPC int, operandStack *module.OperandStack, localVariableStore *module.LocalVariableStore, callStack *module.CallStack) (int, error) {
	if len(parts) < 2 {
		return 0, errors.New("JUMP: malformed operands")
	}
	targetAddr, err := strconv.Atoi(parts[1])
	if err != nil {
		utils.LogError("Invalid jump target")
		return -1, nil
	}
	utils.LogInfo("Jumping to instruction", parts[1])
	return targetAddr, nil
}
